﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
public partial class aspnet_admin_bock_keyWord_CX_keyWord_Show : System.Web.UI.Page
{
    public TongUse TextData = new TongUse();
    protected void Page_Load(object sender, EventArgs e)
    {

        BindData();

    }

    //看看是不是要删除数据
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");

            l.Attributes.Add("onclick", "javascript:return " +

            "confirm('您确定要删除 " +

            DataBinder.Eval(e.Row.DataItem, "Cx_keyWord_Name") + "吗?')");

        }

    }

    protected void BindData()
    {
        DataTable TempTab = new DataTable();
        TempTab = TextData.SqlataSet("SELECT * FROM [Cx_keyWord] order by Cx_keyWord_id desc").Tables[0];
        GridView1.DataSource = TempTab.DefaultView;
        GridView1.DataBind();
    }


    public  string  CreateCheckBox(string key_id)
    {
        string[] Cx_id;
        string str = "";
        if (key_id != "")
        {

            Cx_id = key_id.Split(',');//以 ' 分开 得到数组

            DataTable KeyClass = TextData.SqlataSet("select CX_keyWord_Class_id,CX_keyWord_Class_Name from [CX_keyWord_Class] ").Tables[0];
            for (int i = 0; i < KeyClass.Rows.Count; i++)
            {



                if (ISCheckBoxCreate(Cx_id, KeyClass.Rows[i]["CX_keyWord_Class_id"].ToString().Trim()))//如果选定
                {
                    str += KeyClass.Rows[i]["CX_keyWord_Class_Name"].ToString().Trim() + "   ,  ";

                }


            }
        }
        return str;

    }

    /// <summary>
    ///  看看数组里是不是存在 这个ID
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    protected bool ISCheckBoxCreate(string[] shuZhu, string id)
    {
        for (int i = 0; i < shuZhu.Length; i++)
        {
            if (id == shuZhu[i])
            {
                return true;
            }
        }
        return false;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        GridView1.DataSource = TextData.SqlataSet("select * from [Cx_keyWord]  where Cx_keyWord_Name like '%" + Cx_keyWord_Name.Text.Trim() + "%' order by Cx_keyWord_id desc").Tables[0].DefaultView; 
        GridView1.DataBind();
    }

    /// <summary>
    /// 编辑事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void KeyWord_edit_Click(object sender, EventArgs e)
    {
        string RedirID = ((LinkButton)sender).CommandArgument.ToString();
        if (RedirID != "")
        {
            Response.Redirect("CX_keyWord_Edit.aspx?id=" + RedirID);
        }
    }

    /// <summary>
    /// 分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void pagechange(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = TextData.SqlataSet("SELECT * FROM [Cx_keyWord] order by Cx_keyWord_id desc").Tables[0].DefaultView; ;
        GridView1.DataBind();
    }

    /// <summary>
    /// 删除事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void delcc(object sender, EventArgs e)
    {

        string RedirID = ((LinkButton)sender).CommandArgument.ToString();
        if (RedirID != "")
        {
            try
            {
                TextData.SqlDataSave("delete [Cx_keyWord] where Cx_keyWord_id = " + RedirID);
                tt.Text = "";
                tt.Text = "删除 信息成功" ;
                BindData();
            }
            catch
            {
                tt.Text = "";
                tt.Text = "删除  时出现错误　操作没有完成 ";
            }
        }
    
    }

}
